package com.jing.product.controller;

import com.jing.common.core.domain.R;
import com.jing.common.core.web.controller.BaseController;
import com.jing.common.core.web.page.TableDataInfo;
import com.jing.product.domain.po.PmsProductAttributePO;
import com.jing.product.domain.vo.PmsProductAttributePoVO;
import com.jing.product.service.ProductAttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/attribute")
@Api(tags = "商品属性表")
public class ProductAttributeController extends BaseController {

    @Autowired
    private ProductAttributeService productAttributeService;

    @PostMapping("/findAttribute")
    @ApiOperation("测试商品属性分类")
    public TableDataInfo findAttribute(@RequestParam(required = false,defaultValue = "1")
                                                   Integer pageNum,
                                       @RequestParam(required = false,defaultValue = "2")
                                                   Integer pageSize){
        startPage();
        List<PmsProductAttributePoVO> list = productAttributeService.findAttribute();
        TableDataInfo dataTable = getDataTable(list);
        return dataTable;
    }

    @PostMapping("/add")
    @ApiOperation("添加商品属性")
    public R add(@Valid @RequestBody PmsProductAttributePO productAttribute){
        productAttributeService.add(productAttribute);
        return R.ok("添加商品属性成功");
    }

    @PostMapping("/delect")
    @ApiOperation("删除商品属性")
    public R delect(@Valid @RequestParam String id){
        productAttributeService.delect(id);
        return R.ok("删除商品属性成功");
    }


    @PostMapping("/update")
    @ApiOperation("修改商品属性")
    public R update(@Valid @RequestParam String id){
        productAttributeService.update(id);
        return R.ok("修改商品属性成功");
    }
}
